package com.lagou.test;

import com.lagou.domain.t_article;
import com.lagou.mapper.ArticleMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {

    /*
       一对多关联查询：查询所有用户及关联的订单信息
    */
    @Test
    public void test2() throws IOException {

        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();

        ArticleMapper mapper = sqlSession.getMapper(ArticleMapper.class);

        List<t_article> allArticle = mapper.findAll();

        for (t_article t_article : allArticle) {
            System.out.println(t_article);
            System.out.println(t_article.getT_commentList());
        }

        sqlSession.close();


    }
}
